const {
  banner,
  listbanner
} = require("../../api/user");
const {
  request,
  post
} = require("../../utils/requert");

// pages/router/index.js.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    banner: [],
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    pageNum: 1,
    pageSize: 10,
    loading: false,
    finish: false
  },
  delite(e) {
    console.log(e);
    wx.navigateTo({
      url: `/pages/delit/index?id=${e.currentTarget.dataset.id}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.bannerbox()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.bannerbox().then(res => {
      wx.stopPullDownRefresh({
        success: (res) => {},
      })
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // console.log("111111");
    this.data.pageNum += 1
    banner(this.data.pageNum, this.data.pageSize).then(res => {
      this.setData({
        list: this.data.list.concat(res.data.rows)
      })
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bannerbox() {
    this.data.pageNum = 1
    const bannerpromise = banner().then(res => {
      this.setData({
        list: res.data.rows
      })
    })
    const listbannerpromise = listbanner().then(res => {
      this.setData({
        banner: res.data.rows
      })
    })
    return Promise.all([bannerpromise, listbannerpromise])
  }
})